#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Datetime: 2022/11/24 10:48
# @Author  : CHENWang
# @Site    : 
# @File    : halving_analysis.py
# @Software: PyCharm

"""
脚本说明: 具有减半属性的币走势分析
"""
import os
import numpy as np
import pandas as pd
from quant_researcher.quant.project_tool.localize import DATA_DIR

if __name__ == '__main__':
    file_path = os.path.join(DATA_DIR, 'all_history_ohlcvm_coinmarketcap')
    file_path = os.path.join(file_path, f'all_history_ohlcvm_coinmarketcap')

    log_price_df_list = []
    ret_df_list = []
    cap_df_list = []
    for coins in ['bitcoin', 'litecoin', 'bitcoin-cash', 'bitcoin-sv', 'ethereum-classic', 'dash', 'zcash']:
        file_name = os.path.join(file_path, f'{coins}.xlsx')
        price_df = pd.read_excel(f'{file_name}', index_col='end_date')
        price_series = price_df['close']
        cap_series = price_df['market_cap']
        price_series.name = coins
        cap_series.name = coins
        ret_series = price_series.pct_change()
        log_price_series = np.log10(price_series)
        log_price_df_list.append(log_price_series)
        ret_df_list.append(ret_series)
        cap_df_list.append(cap_series)

    all_log_price_df = pd.concat(log_price_df_list, axis=1)
    all_ret_df = pd.concat(ret_df_list, axis=1)
    all_cap_df = pd.concat(cap_df_list, axis=1)

    file_path = os.path.join(DATA_DIR, f'trading_data')
    file_name = os.path.join(file_path, f'halving_analysis_prices')
    all_log_price_df.to_excel(f'{file_name}.xlsx')
    file_name = os.path.join(file_path, f'halving_analysis_ret')
    all_ret_df.to_excel(f'{file_name}.xlsx')
    file_name = os.path.join(file_path, f'halving_analysis_cap')
    all_cap_df.to_excel(f'{file_name}.xlsx')